package com.mz.ozy.activity.c2c;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.mz.ozy.R;
import com.mz.ozy.adapter.BankListAdapter;
import com.mz.ozy.base.BaseActivity;
import com.mz.ozy.bean.BalanceDetailBean;
import com.mz.ozy.bean.BankListFBean;
import com.mz.ozy.bean.ReceiveAccountBean;
import com.mz.ozy.mvp.presenter.ReceiveAccountPresenter;
import com.mz.ozy.mvp.view.ReceiveAccountContract;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author lifeStyle on 2020/4/18 0018.
 */
public class BankListAcvitity extends BaseActivity<ReceiveAccountContract.View, ReceiveAccountPresenter> implements ReceiveAccountContract.View {

    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;
    @BindView(R.id.ll_no_data)
    LinearLayout llNoData;
    private List<BankListFBean.BankListBean> mBeanList = new ArrayList<>();
    private BankListAdapter mHYRecordAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bank_list);
        ButterKnife.bind(this);

        initTitle();
        mPresenter.getBank(this);
        tvCenterTitle.setText("选择银行");
        mHYRecordAdapter = new BankListAdapter(null);
        recyclerview.setLayoutManager(new LinearLayoutManager(this));
        recyclerview.setAdapter(mHYRecordAdapter);
        mHYRecordAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                BankListFBean.BankListBean data = mHYRecordAdapter.getItem(position);
                Intent intent = new Intent(BankListAcvitity.this, ReceiveAccountActivity.class);
                intent.putExtra("name", data.getName());
                intent.putExtra("id", data.getId()+"");
                setResult(RESULT_OK, intent);
                finish();
            }
        });
    }

    @Override
    public void saveAccountSuccess(BalanceDetailBean bean) {

    }

    @Override
    public void queryAccountSuccess(ReceiveAccountBean bean) {

    }

    @Override
    public void onGetBankSuccess(BankListFBean bean) {

        mBeanList.clear();
        if (bean.getBank_list().size() == 0) {
            llNoData.setVisibility(View.VISIBLE);
        } else {
            llNoData.setVisibility(View.GONE);
        }
        mHYRecordAdapter.setNewData(bean.getBank_list());
    }

    @Override
    public void bindInfo(JSONObject bean) {

    }
}
